<?php

require 'config.php';
require CAMINHO_SERVIDOR.'funcoes.php';
require 'dao/campeonatoDAO.class.php';

$format = strtolower($_GET['format']) == 'json' ? 'json' : 'xml'; //xml is the default
$campeonatoDao = new campeonatoDAO();

$posts = $campeonatoDao->listaAllCampeonatos();
if (empty($msg)) {
    $msg[] = array('msg' => "");
}
if ($format == 'json') {
    header('Content-type: application/json');
    echo json_encode(array('posts' => $posts, 'msgs' => $msg));
} else {
    header('Content-type: text/xml');
    echo '<posts>';
    foreach ($posts as $index => $post) {
        if (is_array($post)) {
            foreach ($post as $key => $value) {
                echo '<', $key, '>';
                if (is_array($value)) {
                    foreach ($value as $tag => $val) {
                        echo '<', $tag, '>', htmlentities($val), '</', $tag, '>';
                    }
                }
                echo '</', $key, '>';
            }
        }
    }
    echo '</posts>';
}
$campeonatoDao->fecharConexao();
?>